package com.core.gwt.place.client;

import com.google.gwt.event.shared.EventBus;

/**
 * A sub-activity which gets attached to a widget embedded in its parent
 * activity's view, rather than bringing its own view.
 * 

 * 
 * @param <V>
 *            the view type
 */
public interface Presenter<V> {
	/**
	 * Attaches the presenter to its widget.
	 * <p>
	 * Any handlers attached to the provided event bus will be un-registered
	 * when the presenter is stopped, so presenters will rarely need to hold on
	 * to the {@link com.google.gwt.event.shared.HandlerRegistration
	 * HandlerRegistration} instances returned by {@link EventBus#addHandler}.
	 * 
	 * @param view
	 *            the widget
	 * @param eventBus
	 *            the event bus
	 */
	void attach(V view, EventBus eventBus);

	/**
	 * Called when the Activity's widget has been removed from view. All event
	 * handlers it registered will have been removed before this method is
	 * called.
	 */
	void detach();

	/**
	 * Called when the user is trying to navigate away from this activity.
	 * 
	 * @return A message to display to the user, e.g. to warn of unsaved work,
	 *         or null to say nothing
	 */
	String mayDetach();
}
